/**
 * RootNode.java
 * Idea
 * @version version 1.0
 *
 * @author     Danny Ayers
 * @created    04-Dec-2002
 *
 * Copyright (c) 2002 D.Ayers
 * All rights reserved.
 *
 * For license details see http://ideagraph.net/licenses
 */
package com.idea.rdftree;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.tree.TreeNode;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.idea.resources.tree.TreeIcons;


/**
 * @author danny
 *
 * created : 04-Dec-2002
 *
 * (c) D.Ayers 2002
 */
public class RootNode extends AbstractRdfTreeNode implements RdfTreeNode {

    private List children;

    public RootNode(RdfNodeMap nodeMap) {
       super(nodeMap,null);
    }
    
	public RDFNode getRdfNode(){
		return null;
	}

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#getChildAt(int)
     */
    public TreeNode getChildAt(int childIndex) {
        //	System.out.println("root.getChildAt "+childIndex);
        //	System.out.println(".getChildAt = "+(TreeNode) getChildren().get(childIndex));
        return (TreeNode)getChildren().get(childIndex);
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#getChildCount()
     */
    public int getChildCount() {
        return getChildren().size();
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#getParent()
     */
    public TreeNode getParent() {
        return null;
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#getIndex(TreeNode)
     */
    public int getIndex(TreeNode node) {
        return getChildren().indexOf(node);
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#getAllowsChildren()
     */
    public boolean getAllowsChildren() {
        return true;
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#isLeaf()
     */
    public boolean isLeaf() {
        //System.out.println("rootkids = " + getChildren().size());
        return getChildren().size() == 0;
    }

    /* (non-Javadoc)
     * @see javax.swing.tree.TreeNode#children()
     */
    public Enumeration children() {
        return (new Vector(getChildren())).elements();
    }

    protected List getChildren() {
    //	System.out.println("GET children base root node");
        if(children == null) {
            try {
                children = new ArrayList();

                Model model = getNodeMap().getTopModel();
                Iterator iterator = getNodeMap().getResources().iterator();
                Resource resource;

                while(iterator.hasNext()) {
                    resource = (Resource)iterator.next();

                    children.add(getNodeMap().getResourceNode(resource));
                }
            } catch(Exception exception) {
                exception.printStackTrace();
            }
        }

        return children;
    }

    public String toString() {
        return "";
    }

    public ImageIcon getIcon() {
        return TreeIcons.rootIcon;
    }

	public int getNodeType() {
		return RdfTreeNode.ROOT;
	} 
	
	public void delete() {
		System.out.println("MUST NOT DELETE ROOT NODE");
	}

	public void rename(String newName) {
		System.out.println("MUST NOT RENAME ROOT NODE");
	}
}
